<script src="__PUBLIC__/ganged/Js/city-picker.data.js"></script>
<script src="__PUBLIC__/ganged/Js/city-picker.js"></script>
<script src="__PUBLIC__/ganged/Js/main.js"></script>
<!-- css -->
<link href="__PUBLIC__/ganged/Css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/ganged/Css/city-picker.css" rel="stylesheet" type="text/css" />

<link href="__PUBLIC__/admin/datetimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/datetimepicker/bootstrap-datetimepicker.min.js" ></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/datetimepicker/bootstrap-datetimepicker.zh-CN.js" ></script>

<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/uploadify/jquery.uploadify.min.js" ></script>
<link rel="stylesheet" charset="utf-8" type="text/css" href="__PUBLIC__/admin/js/uploadify/uploadify.css"> 
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/admin/js/upload.js" ></script>
<!-- 定位 -->
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=yWnFso0oyjmX79HzCx1DRz2sBtvweQfI"></script>
<style>
.bg{ background: none; border: none;}
.uploadify-button-text{ display: inline-flex; }
.uploadify-button-text button{ margin: -10px; }
.upviewer img{ height:90px; width: 120px; }
.upviewer ul{ margin:0px; padding:0px; }
.upviewer li{ margin:0px; padding:0px; position: relative; display:inline-block; width:120px; height:90px; background-position: center; background-size: contain; background-repeat: no-repeat; float: left; margin-right:10px; border:1px #ccc solid; background-color:#f0f0f0;}
.upviewer li a{ display:inline-block; position: absolute; bottom:0px; left:0px; text-align:center; width:100%; background-color:rgba(0,0,0,0.3); color:red; cursor: pointer; }
.upviewer li:hover a{ background-color:rgba(0,0,0,0.8); }
</style>
<div class="container" style="padding-top: 50px;">
	<div class="row clearfix">
		<div class="col-md-12 column">
			<form class="form-horizontal" role="form" id="post_form" action="{:U('add')}">
                <div class="form-group">
                     <label for="title" class="col-sm-2 control-label">经销商名称:<span style="color: red;">*</span></label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="shop_name" id="shop_name"/>
                    </div>
                </div>
                <div class="form-group">
                     <label for="title" class="col-sm-2 control-label">品牌名称:<span style="color: red;">*</span></label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="brand_name" id="brand_name"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="title" class="col-sm-2 control-label">姓名:<span style="color: red;">*</span></label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="name" id="name"/>
                    </div>
                </div>
                <div class="form-group">
                     <label for="title" class="col-sm-2 control-label">联系电话:<span style="color: red;">*</span></label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="mobile" id="mobile"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="instructions" class="col-sm-2 control-label">须知:</label>
                    <div class="col-sm-5" >
                    <textarea class="form-control" name="instructions" id="instructions" rows="10"></textarea>
                    </div>
                </div>
                <!-- 省市三级联动 -->
                    <div class="form-group">
                    <label for="ds" class="col-sm-2 control-label">省市区:<span style="color: red;">*</span></label>
                    <div id="distpicker" style="margin-left:20%">
                        <div class="form-group">
                            <div style="position: relative;">
                                <input id="city-picker3" class="form-control" readonly type="text" value="" data-toggle="city-picker" style="width:400px;">
                            </div>
                        </div>
                        <div class="form-group">
                            <button class="btn btn-warning" id="reset" type="button">重置</button>
                            <button class="btn btn-danger" id="destroy" type="button">确定</button>
                        </div>
                    </div>
                    </div>
                <!-- 三级联动结束 -->

                <div class="form-group">
                    <label for="address" class="col-sm-2 control-label">详细地址:<span style="color: red;">*</span></label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="address" id="address"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="lng" class="col-sm-2 control-label">经度:<span style="color: red;">*</span></label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="lng" id="lng"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="lat" class="col-sm-2 control-label">纬度:<span style="color: red;">*</span></label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control" name="lat" id="lat"/>
                    </div>
                </div>
                <div class="form-group">
                    <label for="picture" class="col-sm-2 control-label">列表图片(300x80):<span style="color: red;">*</span></label>
                    <div class="col-sm-10 js_upload_img">
                        <input type="file" class="form-control" id="picture"><br /> 
                        <div name="picture" class="upviewer">
                            <ul></ul>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="desc_img" class="col-sm-2 control-label">经销商介绍(640x100):<span style="color: red;">*</span></label>
                    <div class="col-sm-10 js_upload_img">
                        <input type="file" class="form-control" id="desc_img"><br /> 
                        <div name="desc_img" class="upviewer">
                            <ul></ul>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="pictures" class="col-sm-2 control-label">轮播(640x260):<span style="color: red;">*</span></label>
                    <div class="col-sm-10 js_upload_imgs">
                        <input type="file" class="form-control" id="pictures"><br /> 
                        <div name="pictures" class="upviewer">
                            <ul></ul>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="boss_img" class="col-sm-2 control-label">老板照片:</label>
                    <div class="col-sm-10 js_upload_imgs">
                        <input type="file" class="form-control" id="boss_img"><br /> 
                        <div name="boss_img" class="upviewer">
                            <ul></ul>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="business_license" class="col-sm-2 control-label">营业执照:</label>
                    <div class="col-sm-10 js_upload_imgs">
                        <input type="file" class="form-control" id="business_license"><br /> 
                        <div name="business_license" class="upviewer">
                            <ul></ul>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                     <label for="ds" class="col-sm-2 control-label">所属管理员:</label>
                    <div class="col-sm-2">
                        <select name="admin_id" class="form-control"> 
                            <option value="0">请选择管理员</option>
                            <volist name="admin_arr" id="vo">
                                <option value="{$key}">{$vo}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">1小时送达:</label>
                    <div class="col-sm-10">
                        <label for="is_auth1" class="control-label">
                            <input type="radio" id="is_auth1" name="is_auth" value="0">否
                        </label>
                        <label for="is_auth2" class="control-label">
                            <input type="radio" id="is_auth2" name="is_auth" value="1"  checked>是
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">管长:</label>
                    <div class="col-sm-10">
                        <label for="is_gz1" class="control-label">
                            <input type="radio" id="is_gz1" name="is_gz" value="0" <if condition="$info['is_gz'] neq 1">checked</if>>否
                        </label>
                        <label for="is_gz2" class="control-label">
                            <input type="radio" id="is_gz2" name="is_gz" value="1"  <if condition="$info['is_gz'] eq 1">checked</if>>是
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">采集会员:</label>
                    <div class="col-sm-10">
                        <label for="member_grade1" class="control-label">
                            <input type="radio" id="member_grade1" name="member_grade" value="0">否
                        </label>
                        <label for="member_grade2" class="control-label">
                            <input type="radio" id="is_status2" name="member_grade" value="1">普通会员
                        </label>
                        <label for="member_grade2" class="control-label">
                            <input type="radio" id="is_status2" name="member_grade" value="2">Vip会员
                        </label>
                    </div>
                </div>
                <div class="form-group">
                     <label for="title" class="col-sm-2 control-label">采集会员到期时间:<span style="color: red;">*</span></label>
                    <div class="col-sm-5">
                        <input type="text" class="form-control form_datetime" name="member_expire" id="member_expire"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">状态:</label>
                    <div class="col-sm-10">
                        <label for="is_status1" class="control-label">
                            <input type="radio" id="is_status1" name="status" value="0" checked>关闭
                        </label>
                        <label for="is_status2" class="control-label">
                            <input type="radio" id="is_status2" name="status" value="1">开启
                        </label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" class="btn btn-primary" id="btn" lng="0" lat="0">提交</button>
                    </div>
                </div>
			</form>
		</div>
</div>
<script>
function getPlace(addr, callback) {
    var myGeo = new BMap.Geocoder();
    var lng = 0;
    var lat = 0;
    myGeo.getPoint(addr, function(point) {
        if(point) {
            lng = point.lng;
            lat = point.lat;
        }
        callback({'lat':lat, 'lng':lng})
    });
}	
$(function(){
	 
    $(".form_datetime").datetimepicker({format: 'yyyy-mm-dd hh:ii', 'language':'zh-CN'});

	$("#btn").click(function(){
            // 省市区
			var pcd = $("#city-picker3").val();
			var $form = $("#post_form");
            var $data = {};
            var $form_data = $form.serializeArray();
            $.each($form_data, function(k, v){
                $data[v['name']] = v['value'];
            })
            $data['pcd'] = pcd;
            
            var submit = function(point){
                if(typeof(point['lat']) != 'undefined'){
                    $data['lat'] = point['lat'];
                }
                if(typeof(point['lng']) != 'undefined'){
                    $data['lng'] = point['lng'];
                }
                
                // $data['lat'] = typeof(point['lat']) != 'undefined' ? point['lat'] : 0;
                // $data['lng'] = typeof(point['lng']) != 'undefined' ? point['lng'] : 0;
                $.post($form.attr('action'), $data, function(obj){
                    alert(obj.m);
                    if(obj.s){
                        if(typeof(obj.url)!= "undefined" && obj.url){
                            location.href = obj.url;
                        }
                    }
                })
            }
            // address = pcd.split("/").join("")+$data['address'];
            // if(address){
            //     // 获取经纬
            //     getPlace(address, submit);
            // }else{
                submit({});
            // }
		})
	});
</script>
